package com.helloscala.web

import scala.xml.NodeSeq

import net.liftweb.http.Templates
import net.liftweb.util.Helpers._
import net.liftweb.util.CssSel

import com.helloscala.helper.{HelloHelpers, MicroChat}
import com.helloscala.model.MessageTrait

object MicroChatHelpers {

  def chatLi(mc: MicroChat): NodeSeq = {
    // TODO Comet中不能访问S对像？
    val userHref = W.hrefUser(mc.chat.creator)

    val cssSel =
      ".user-avatar" #> (
        "a [href]" #> userHref
        ) &
        ".user-info" #> (
          "@account [href]" #> userHref &
            "@account *" #> (mc.chat.creator + "：") &
            "@content *" #> mc.chat.content &
            "@time *" #> HelloHelpers.timeDescription(mc.chat.created_at) &
            "@reply" #> mc.reply
          )

    cssSel(nodeChatLi)
  }

  def portrait(mc: MessageTrait): CssSel =
    "a [href]" #> W.hrefUser(mc.creator)

  def nodeChatLi = Templates(List("p", "micro_chat", "_micro_chat_li")).openOrThrowException("/p/micro_chat/_micro_chat_li not found!!!")
}
